#include <iostream>
#include <vector>
#include <cassert>

using namespace std;

/**
 * 有序整型数组查找两个元素和 为target,返回索引,从1开始
 * O(n^2)
 */
class Solution{
	public:
		vector<int> twoSum(vector<int>& numbers,int target){
			assert(numbers.size() >= 2);
			assert(isSorted(numbers));
			for(int i = 0; i < numbers.size(); ++i){
				for(int j = i + 1; j < numbers.size(); ++j){
					if(numbers[i] + numbers[j] == target){
						int res[2] = {i + 1, j + 1};
						return vector<int>(res, res + 2);
					}
				}
			}
			throw invalid_argument("the input has no solution");
		}
	
	private:
		bool isSorted(const vector<int>& numbers){
			for(int i = 1; i < numbers.size(); ++i){
				if(numbers[i] < numbers[i - 1]){
					return false;
				}
			}
			return true;
		}
};
